README: Model Estimation and Simulation Code

Overview
This replication package contains the Fortran source code for estimating the structural model and conducting simulations described in “Health Shocks, Health Insurance, Human Capital, and the Dynamics of Earnings and Health” by Capatina and Keane. 
The code is written in Fortran 90/95 and has been compiled using Intel Visual Fortran Compiler integrated with Microsoft Visual Studio 2017.

System Requirements
- Compiler: Intel Visual Fortran Compiler (tested with Visual Studio 2017)
- Operating System: Windows (tested on Windows 10)
- Dependencies: Standard Fortran libraries only

Directory Structure

Model/
├── List of experiments.xlsx
├── Fortran Code/
│   ├── Benchmark_W/
│   ├── Experiments/
│   └── Counterfactuals/

File Descriptions

Root Directory (Model/)
- "List of experiments.xlsx": Master documentation mapping experiment numbers to their corresponding model modifications. 

Source Code (Fortran Code/)

A. Benchmark Model (Benchmark_W/)
Contains the baseline implementation for the white demographic group. This serves as the reference implementation with full documentation.

Core Files:
- Valuefunction_annual.f90: Main code solving the value functions
- Simulation_annual.f90: Simulation 
- Parameters.f90: Parameter declarations and type definitions
- Functions_libs.f90: Utility functions and mathematical routines
- Interpolate_func.f90: Interpolation algorithms for value function approximation
- Random.f90: Random number generation 
- My_tools.f90: Additional computational utilities

Parameter Directories:
- External_Parameters/: Externally estimated parameters (from data estimation)
- Internal_Parameters/: Calibrated and assumed parameter values

Output Directory:
- Simulated_Data/: Generated datasets, random draws, and simulation results

Note: The benchmark specification corresponds to jExperimentNumber=0 in the code.

B. Experiments (Experiments/)
Contains implementations of counterfactual scenarios where decision rules remain unchanged but agents experience different realizations of stochastic processes.

Subdirectories by Demographic Group:
- Experiments_W1/: First experimental set for Whites (marked in blue in documentation (see "List of experiments.xlsx"))
- Experiments_W2/: Second experimental set for Whites (marked in green in documentation (see "List of experiments.xlsx"))
- Experiments_B/: Experiments for Blacks
- Experiments_H/: Experiments for Hispanics

C. Structural Counterfactuals (Counterfactuals/)
Contains implementations where we change the model environment and new optimal decision rules are solved.

Implementation Notes:
- Parameter modifications implemented via conditional statements keyed to jExperimentNumber
- Agents re-optimize given the modified economic environment
- Comments have been removed for brevity; refer to Benchmark_W/ for annotated code

Execution Protocol

1. Baseline Estimation
Execute the benchmark model (jExperimentNumber=0) to generate:
- The simulated data for the Benchmark
- Initial random number sequences for ages 25-64 (Random_numbers0.txt)

2. Preparation for Experiments
1. Run Experiment 21 (jBenchmark_exp=21) to generate extended random draws (used for simulations at ages 65+) and histories of health, savings and labor market outcomes for simulated individuals
2. Copy the following files to all experimental directories:
   • Random_numbers0.txt (working-age random draws)
   • Random_numbers_old0.txt (retirement-age random draws)

3. Experimental Execution
Execute experiments and counterfactuals in any order, ensuring consistent random number seeds across scenarios.

Special Cases
- Counterfactual 16 (jExperimentNumber=16): Replicates baseline conditions but outputs additional welfare measures and utility calculations for policy evaluation.

Important: This protocol must be completed separately for each racial group.

Output Files
All simulation results are saved to their respective Simulated_Data/ directories. Post-processing and statistical analysis are conducted using STATA.
To process the data:

Set the appropriate paths in the STATA dictionary files to point to the respective Simulated_Data/ directories in Model/
Run the STATA do-files located in /Data/Simulated data/ subfolders. 